﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace  DoFactory.GangOfFour.Abstract.Structural
{
    public class ObjectPoolMasini 
    {
        private static ObjectPoolMasini _instance ;

        public List<AbstractMasina> _masini;
        private static int max_pool = 10;

        public static ObjectPoolMasini getInstance(AbstractFactory factory1, AbstractFactory factory2, AbstractFactory factory3)
        {
            _instance = new ObjectPoolMasini(factory1, factory2, factory3);
            return _instance;
        }

        private ObjectPoolMasini(AbstractFactory factory1, AbstractFactory factory2, AbstractFactory factory3)
        {
            _masini = new List<AbstractMasina>();

            bool da = true;
            while (da && _masini.Count<max_pool)
            {
                Console.WriteLine("Tipul masinii:\n1.Sedan\n2.Mini\n3.Coupe");
                int tip = Int32.Parse(Console.ReadLine());
                
                if (tip == 1)
                {
                    AbstractMasina nou = (Sedan)factory1.CreateMasina();
                    _masini.Add(nou);
                }
                else
                    if (tip == 2)
                    {
                        AbstractMasina nou = (Mini)factory2.CreateMasina();
                       _masini.Add(nou);
                    }
                    else
                        if (tip == 3)
                        {
                            AbstractMasina nou = (Coupe)factory3.CreateMasina();
                            _masini.Add(nou);
                        }

                Console.WriteLine("Mai introduceti o masina? (d / n)");
                da = (Console.ReadLine().CompareTo("d") == 0 ? true : false);
            }
        }

    }
}
